package com.qianfeng.xiaxk.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;


public class SplashUtils {
    /**
     * 判断应用程序是否是第一次运行
     *
     * @param context
     * @return 版本号
     */
    public static boolean isFirst(Context context) {
        SharedPreferences sp = context.getSharedPreferences("isFirst", Context.MODE_PRIVATE);
        boolean isFirst = sp.getBoolean("isFirst", true);
        if (isFirst) {
            sp.edit().putBoolean("isFirst", false).commit();
            sp.edit().putInt("versionCode", getVersionCode(context)).commit();
        }
        return isFirst;
    }

    /**
     * 获取当前应用的版本号
     *
     * @param context
     * @return
     */
    private static int getVersionCode(Context context) {
        PackageManager manager = context.getPackageManager();
        PackageInfo info = null;
        try {
            info = manager.getPackageInfo(context.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return info.versionCode;

    }


}
